import logging

import pytest

from resource.pom.settings import Settings


class Test:
    app = Settings

    @pytest.mark.parametrize('setup_teardown', [app.bundle_name], indirect=True)
    def test(self, setup_teardown, device):
        logging.info('步骤1.点击设置应用')
        device.set_brightness(1)
        device.start_ability(self.app.bundle_name, self.app.ability_name)
        logging.info('预期结果1.进入设置应用')
        device.assert_current_window(self.app.window_name)

        logging.info('步骤2.点击显示与亮度')
        device.click(*self.app.display_brightness_item)
        logging.info('预期结果2.进入显示与亮度')
        device.refresh_layout()
        device.assert_text_exist('亮度')
        device.assert_type_exist('Slider')

        logging.info('步骤3.左右滑动亮度滚动条')
        brightness0 = device.display_screen_status().get('brightness')
        slider = device.get_element_by_type('Slider')
        x1, y1, x2, y2 = device.get_element_area(slider)
        device.swipe(x1 + 50, (y1 + y2) // 2, x2 - 50, (y1 + y2) // 2)
        device.wait(0.5)
        brightness1 = device.display_screen_status().get('brightness')
        device.swipe(x2 - 50, (y1 + y2) // 2, x1 + 50, (y1 + y2) // 2)
        device.wait(0.5)
        brightness2 = device.display_screen_status().get('brightness')
        logging.info('预期结果3.屏幕亮度按实际情况变化，左滑变暗右滑变亮')
        assert brightness1 > brightness0, f'右滑操作亮度变化{brightness0}->{brightness1}，不符合预期'
        assert brightness1 > brightness2, f'左滑操作亮度变化{brightness1}->{brightness2}，不符合预期'
